import { apiTmpStr } from '@/utils/swaggerUtil/swaggerData'
// 传入swagger数组返回api接口字符串
export function apiSwaggerToStr(listArr, tableName = '', swaggerConfig, definitions) {
  let str = swaggerConfig.importPath ? `${swaggerConfig.importPath}\n` : 'import request from \'@/utils/request\';\n'
  let exportFunStr = listArr.map(x => x.name).join(',')
  let exportParams = `\n/** 导出${tableName}接口 
  \n
  import  { ${exportFunStr} } from "@/api/${tableName}/index"
  \n
  */
  \n
 `
  str = str + exportParams
  console.log('listArr', listArr)
  listArr.forEach((item) => {
    let config = {
      ...item,
      summary: item.methodName,
    }
    // debugger
    let apiStr = apiTmpStr({
      requestName: 'request',
      config,
      definitions,
    })

    str += `${apiStr}`
  })
  return str
}
// 传入swagger数组返回api接口字符串
export function buildApiFile(path, fileText) {
  return {
    type: 'js',
    label: path,
    id: path,
    fileText,
  }
}
